package io.gitee.zhucan123.core.infrastructure.dataconversion.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.niimbot.middlend.core.config.JsonConfiguration;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author: zhuCan
 * @date: 2020/2/25 14:05
 * @description:
 */
public class JacksonLocalDateSerializer extends JsonSerializer<LocalDateTime> {
  @Override
  public void serialize(LocalDateTime localDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    jsonGenerator.writeString(DateTimeFormatter.ofPattern(JsonConfiguration.PATTERN).format(localDateTime));
  }
}
